﻿using Beetle;
using Smark.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

internal class Class_i
{
    public IMessageHandler _field_a;
    public MethodHandler _field_b;
    public Type _field_c;
    private static Hashtable _field_d = new Hashtable(0x200);

    public static IList<Class_i> d(IMessageHandler A_0)
    {
        lock (_field_d)
        {
            Type type = A_0.GetType();
            List<Class_i> list = (List<Class_i>) _field_d[type];
            if (list == null)
            {
                list = new List<Class_i>();
                foreach (MethodInfo info in type.GetMethods(BindingFlags.Public | BindingFlags.Instance))
                {
                    ParameterInfo[] parameters = info.GetParameters();
                    if ((parameters.Length == 2) && (parameters[0].ParameterType == typeof(TcpChannel)))
                    {
                        Class_i item = new Class_i {
                            _field_a = A_0,
                            _field_b = new MethodHandler(info),
                            _field_c = parameters[1].ParameterType
                        };
                        list.Add(item);
                    }
                }
            }
            return list;
        }
    }

    public void d(TcpChannel A_0, object A_1)
    {
        MessageHandlerArgs message = new MessageHandlerArgs {
            Message = A_1,
            Cancel = false
        };
        this._field_a.ProcessMessage(A_0, message);
        if (!message.Cancel)
        {
            this._field_b.Execute(this._field_a, new object[] { A_0, A_1 });
        }
    }
}

